.\" Copyright (c) 1994
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"	@(#)getmntopts.3	8.1.1 (2.11BSD) 1996/1/16
.\"
.TH GETMNTOPTS 3 "January 16, 1996"
.UC 7
.SH NAME
\fBgetmntopts\fP \- scan mount options
.SH SYNOPSIS
.B #include <mntopts.h>
.sp
.B void
.br
.B getmntopts(options, mopts, flagp)
.br
.B char *options;
.br
.B struct mntopt *mopts;
.br
.B int *flagp
.SH DESCRIPTION
The
.BR getmntopts ()
function takes a comma separated option list and a list
of valid option names, and computes the bitmask
corresponding to the requested set of options.
.PP
The string
.I options
is broken down into a sequence of comma separated tokens.
Each token is looked up in the table described by
.I mopts
and the bits in
the word referenced by
.I flagp
are updated.
The flag word is not initialized by
.BR getmntopt .
The table,
.IR mopts ,
has the following format:
.sp
.cs R 24
.nf
struct mntopt {
	char *m_option;		/* option name */
	int m_inverse;		/* is this a negative option, eg "dev" */
	int m_flag;		/* bit to set, eg MNT_RDONLY */
};
.br
.fi
.cs R
.PP
The members of this structure are:
.sp
.TP 10
\fIm_option\fP
the option name,
for example
``suid''.
.TP 10
\fIm_inverse\fP
tells
.B getmntopts
that the name has the inverse meaning of the
bit.
For example,
``suid''
is the string, whereas the
mount flag is
MNT_NOSUID.
In this case, the sense of the string and the flag
are inverted, so the
.I m_inverse
flag should be set.
.TP 10
\fIm_flag\fP
the value of the bit to be set or cleared in
the flag word when the option is recognized.
The bit is set when the option is discovered,
but cleared if the option name was preceded
by the letters
``no''.
The
.I m_inverse
flag causes these two operations to be reversed.
.PP
Each of the user visible
.I MNT_
flags has a corresponding
.I MOPT_
macro which defines an appropriate
.I "struct mntopt"
entry.
To simplify the program interface and ensure consistency across all
programs, a general purpose macro,
.IR MOPT_STDOPTS ,
is defined which
contains an entry for all the generic VFS options.
In addition, the macros
.I MOPT_FORCE
and
.I MOPT_UPDATE
exist to enable the
.I MNT_FORCE
and
.I MNT_UPDATE
flags to be set.
Finally, the table must be terminated by an entry with a NULL
first element.
.SH EXAMPLES
Most commands will use the standard option set.
Local filesystems which support the
.I MNT_UPDATE
flag, would also have an
.I MOPT_UPDATE
entry.
This can be declared and used as follows:
.sp
.nf
.cs R 24
#include "mntopts.h"

struct mntopt mopts[] = {
	MOPT_STDOPTS,
	MOPT_UPDATE,
	{ NULL }
};

	...
	mntflags = 0;
	...
	getmntopts(options, mopts, &mntflags)
	...
.br
.fi
.cs R
.SH DIAGNOSTICS
The
.B getmntopts
function displays an error message and exits if an
unrecognized option is encountered.
.SH SEE ALSO
err(3),
mount(8)
.SH HISTORY
The
.B getmntopts
function appeared in 4.4BSD.
